package liziy.spring.context.annotation;


import liziy.spring.context.support.GenericApplicationContext;

/**
 * 初始化Spring 默认的容器对象
 * @author Liziy
 * @date 2020/12/15 23:04
 **/
public class AnnotationConfigApplicationContext extends GenericApplicationContext {
    private AnnotatedBeanDefinitionReader reader;
    private ClassPathBeanDefinitionScanner scanner;

    public AnnotationConfigApplicationContext() {
        this.reader = new AnnotatedBeanDefinitionReader(this);
        this.scanner = new ClassPathBeanDefinitionScanner(this);
    }
    /**
     * 初始化扫描包的构造函数
     * @param basePackage
     */
    public AnnotationConfigApplicationContext(String... basePackage) {
        //初始化筛选前数据
        this();
        //执行扫描条
        scan(basePackage);
        refresh();
    }

    private void scan(String... basePackages) {
        if (basePackages.length == 0){
            return;
        }
        this.scanner.scan(basePackages);
    }
}
